package com.ruoyi.web.controller.vantController.customerController;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.domain.customer.CustomerLogin;
import com.ruoyi.system.domain.customer.OwnerEvaluation;
import com.ruoyi.system.service.vantservice.customerervice.OwnerEvaluationService;
import com.ruoyi.system.utils.TokenUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/api/evaluation")
public class OwnerEvaluationController {

    @Autowired
    private OwnerEvaluationService ownerEvaluationService;
    @Autowired
    private TokenUtils tokenUtils;
    @Autowired
    private HttpServletRequest request;
    /**
     * 查询业主评价列表
     */

    @GetMapping("/list")
    public List<OwnerEvaluation> list(OwnerEvaluation ownerEvaluation)
    {
        List<OwnerEvaluation> list = ownerEvaluationService.selectOwnerEvaluationList(ownerEvaluation);
        return list;
    }



    /**
     * 获取业主评价详细信息
     */
    @GetMapping(value = "/getinfo/{ownerId}")
    public AjaxResult getInfo(@PathVariable("ownerId") Long ownerId)
    {
        return AjaxResult.success(ownerEvaluationService.selectOwnerEvaluationById(ownerId));
    }

    /**
     * 新增业主评价
     */
    @PostMapping(value = "/add")
    public AjaxResult add(@RequestBody OwnerEvaluation ownerEvaluation)
    {
        ownerEvaluation.setOwnerDate(new Date());
        ownerEvaluation.setOwnerStatus(1);
        ownerEvaluation.setModifiedTime(new Date());
        // 获取前台登录用户信息
        CustomerLogin customerLogin = tokenUtils.getLoginCustomer(request);
        ownerEvaluation.setCutomerId(customerLogin.getCustomerId());
        return AjaxResult.success(ownerEvaluationService.insertOwnerEvaluation(ownerEvaluation));
    }



}
